from aiohttp import ClientSession, ClientTimeout


class APIClient:
    """
    异步接口api封装
    """
    def __init__(self, base_url: str):
        self.base_url = base_url

    async def post(self, endpoint: str, headers: dict, json: dict) -> dict:
        """异步发送 POST 请求"""
        async with ClientSession(timeout=ClientTimeout(total=10)) as session:
            async with session.post(f"{self.base_url}{endpoint}", headers=headers, json=json) as response:
                response_json = await response.json()
                # print(response_json)
                return response_json
